<?php
/**
 * <https://y.st./>
 * Copyright © 2018 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'<{title}>' => 'Too many possible solutions',
	'takedown' => '2017-11-01',
	'<{body}>' => <<<END
<img src="/img/CC_BY-SA_4.0/y.st./weblog/2018/12/09.jpg" alt="Trees along the road" class="framed-centred-image" width="649" height="480"/>
<section id="drudgery">
	<h2>Drudgery</h2>
	<p>
		My discussion post for the day:
	</p>
	<blockquote>
		<p>
			You&apos;re right.
			When we pass arguments by value, instead of by reference, we&apos;re unable to change the value of the variable as it&apos;s seen outside our function.
			This is very useful, as it means we don&apos;t have to be as careful.
			We don&apos;t have to worry about accidentally changing the value and causing unexpected results.
			Like you said, that kind of bug can be very difficult to locate and fix.
		</p>
		<p>
			I agree about recursion and efficiency.
			It really isn&apos;t an efficient way for the computer to do anything.
			However, it&apos;s an efficient way for the programmer to think about the problem.
			When developer time has more of a premium, recursion can be the right tool for the job.
			When computer resources have more of a premium though, it&apos;s probably best to leave recursion alone.
		</p>
		<p>
			By the way, you told us you chose the sorting problem, but didn&apos;t really tell us how you&apos;d solve it with recursion.
			How would you choose to implement recursion in sorting something?
		</p>
	</blockquote>
</section>
<section id="Minetest">
	<h2>Minetest</h2>
	<p>
		I don&apos;t know what I&apos;ve done with my palette textures and the code that powered both dye-mixing and dying.
		I started work on a converter between my palette and VanessaE&apos;s, only to find my palette had entirely gone missing.
		Luckily, I have the working draft of my palette on my desktop still.
		My desktop is such a mess right now and really needs to be cleaned up.
		But anyway, to get my main (large) palette back, I pretty much just need to trim away the unused pixels around the palette.
		The mid-sized palette can be gotten by cutting off a chunk of the main palette, and the small palette is gotten by moving a few of the pixels and trimming again.
		So I don&apos;t have to do all the colour-finding work again.
		I&apos;ve got copies of old code from when my palette idea was going to be a part of <code>alchemy</code>, so I can derive from that, but my newer work is just gone.
		Where did I put it?
		This is frustrating.
	</p>
	<p>
		I started building a script to try to find the best possible match between VanessaE&apos;s palette and my own.
		This would allow me to support both palettes.
		Not only would this support apply to the <code>blockprotectnodes</code> mod I&apos;m trying to complete a release for now, but also any other mod I develop with coloured nodes.
		The worst part, or so I thought, was copying all the colour numbers from the palettes to some code.
		I don&apos;t know how to have a program read the colours out of an image, so I had to open up the $a[GIMP] and start reading the colour numbers by hand, typing them into the script.
		Halfway through, I had to quit and go to work.
		I figured I&apos;d finish when I got home, then run the script while I slept.
	</p>
	<p>
		The script was set up to brute force a solution, as I wasn&apos;t sure how else to solve the problem.
		It&apos;d check every translation possibility, and look for the one or ones with the least cubes difference between my palette and VanessaE&apos;s.
		That would get the colours as close as I could get them, while not letting some colours unduly push other colours to radically-different translations.
		Some colours might be a bit further off than they could be, but on the whole, the full palette would be as close as possible.
		At work though, I realised that I needed some idea of how long this would take to run.
		To start with, I wanted to know how many possible solutions would need to be tried.
		So when I got home, I pulled up a calculator and asked it for <code>256!</code>.
		The palettes have <code>256</code> colours, so there would be <code>256!</code> translation options.
		DO you know what the calculator told me?
		It told me the number of options is equal to a <code>507</code>-digit number!
		And on the high end of that range, too.
		I planned to look up exactly how to do the least cubes thing in case I misremembered, but I think it requires adding three cubes and taking the cube root.
		For each of the <code>256</code> colours.
		That&apos;s way too many cubes and cube roots.
		Would I even be able to complete a run of the script in under a week?
		I shut my laptop off every Thursday to take it to $a[EUGLUG] meetings, so the machine doesn&apos;t stay on for even a full week at a time.
		Shutting the machine down obviously would undo any progress done by the script, and I&apos;d have to start over.
		Every week.
		So it would never complete.
	</p>
	<p>
		I finally figured out the proper way to solve the problem.
		Brute force really is just a tool for when you don&apos;t know how to properly solve a problem.
		The least cubes thing was designed with the visualisation of a three-dimensional colour space in mind.
		The point was to find which points from one palette were closest to what colours in the other palette, physical-distance-wise in this visualisation.
		So what I need to do is arrange the data as it would be in this colour space.
		I need to finish copying the data from VanessaE&apos;s palette into the script.
		(I already finished copying the data from my own palette.)
		Then I&apos;ll have the computer sort the data for both palettes, which will take a few seconds, tops, but will more likely be completed nearly instantly.
		With the data sorted, I can get a better idea of what I&apos;m dealing with, and can probably complete the rest of the translation by hand.
		Vanessae&apos;s palette&apos;s colours can&apos;t be arranged in a very grid-like way, as far as I can tell, but my palette&apos;s colours very much can.
		Working from that grid, it hopefully won&apos;t be too difficult to find the correct colours to match with from her&apos;s.
	</p>
</section>
END
);
